//购物车
 var ParcelRate = $.cookie("ParcelRate");
 var RingRate=$.cookie("RingRate");
 var GemRate=$.cookie("GemRate");
 var EmeraldRate=$.cookie("EmeraldRate");
var PrimeGoldRate=$.cookie("PrimeGoldRate");
var inlaysettingsRate=$.cookie("InlaySettingsRate");
var id;
(function(){
	var cart={
		init:function(){
			args = GetUrlParms();				
			if(args["type"]!=undefined){						
				 TYPE = args["type"];//产品类型				
			}
			this.bindEvents();
			this.getCustomer(0);
			this.getSales();
		},
		bindEvents:function(){
			var self=this;
			$('.wrapper').navbarscroll();
			//查看
			$("#cart_body").on("click",".look_cart",function(){
				if(TYPE=="1"){//裸钻
	            	myApp.popup(".stock_cart_box");
	            }else if(TYPE=="2"){//统包
	            	myApp.popup(".parcel_cart_box");
	            }else if(TYPE=="3"){//成品
	            	myApp.popup(".inlay_cart_box");
	            }else if(TYPE=="4"){//彩宝
	            	myApp.popup(".gem_cart_box");
	            }else if(TYPE=="5"){//翡翠
	            	myApp.popup(".emerald_cart_box");
	            }else if(TYPE=="6"){//素金
	            	myApp.popup(".PrimeGold_cart_box");
	            }else if(TYPE == 7){ //空托
                    myApp.popup(".inlaysettings_cart_box")
                }
				
				id=$(this).attr("data-id");
				self.GetCartInfos(id);//获取当前用户的购物车
			});
			 //点击行展开详情
            $(".cart_body").on("click", "tr.data_tr td", function (event) {
                var td_input = $(this).index();
                if (td_input == 0 || td_input==1) {
                    //勾选框不展开详情
                } else {
                    $(this).parent("tr").next(".stock_detail").slideToggle(0);
                }                 
            });
            //切换购物车类型
            $("#categories a").on("click",function(){
            	TYPE=$(this).attr("data-type");
            	$("#th_check_all_stock_cart").find(".checkbox").removeClass("selected");
            	self.getCustomer();
            });
            //点击搜索
            $("#search_btn").on("click",function(){
            	self.getCustomer(1);
            });
            //提交订单裸钻
			$(".add_order_btn").on("click",function(){
				if($("#cart_stock_body .check_rel span.selected").length>0){
					$("#remark_box").show();
				    myApp.prompt(_("(所有货品一手货源，价格优势，请您放心购买。如遇价格变动或货品不可用，我们会第一时间与您沟通协商。)<br>下单备注："), _('提交订单'), function (value) {
				        self.submitOrder(value);
				    });
				}else{
					myApp.alert(_("请选择"));
				}
			});
            //提交订单统包，成品。。
            $(".add_parcel_btn,.add_rings_btn,.add_inlaysettings_btn").on("click",function(){
            	var addLength="";
            	if(TYPE==2){
                    addLength=$("#parcel_cart_body .check_rel span.selected").length;
				}else if(TYPE==3){
                    addLength=$("#inlay_cart_body .check_rel span.selected").length;
				}else if(TYPE==7){
                    addLength=$("#inlaysettings_cart_body .check_rel span.selected").length;
                }

				if(addLength>0){
					$("#remark_box").show();
					myApp.prompt(_("(所有货品一手货源，价格优势，请您放心购买。如遇价格变动或货品不可用，我们会第一时间与您沟通协商。)<br>下单备注："), _('提交订单'), function (value) {
						self.submitOrderNew(value);
					});
				}else{
					myApp.alert(_("请选择"));
				}

            });
			//删除购物车裸钻
			$(".del_cart_btn").on("click",function(){
				if($("#cart_stock_body .check_rel span.selected").length>0){
					myApp.alert(_("确定移除购物车？"),function(){
						self.delCart();
					});
				}else{
					myApp.alert(_("请选择"));
				}
			});

            //删除客户购物车裸钻
            $("#delete_btn").on("click",function(){
                if($("#cart_body .check_rel span.selected").length>0){
                    myApp.alert(_("确定移除购物车？"),function(){
                        self.delCusIDCart();
                    });
                }else{
                    myApp.alert(_("请选择"));
                }
            });

            //删除购物车统包 成品。。
            $(".del_parcel_btn,.del_rings_btn,.del_inlaysettings_btn").on("click",function(){
            	var dellength="";
            	if(TYPE=="2"){
                    dellength=$("#parcel_cart_body .check_rel span.selected").length;
				}else if(TYPE=="3"){
                    dellength=$("#inlay_cart_body .check_rel span.selected").length;
				}else if(TYPE=="7"){
                    dellength=$("#inlaysettings_cart_body .check_rel span.selected").length;
                }
                if(dellength>0){
                    myApp.alert(_("确定移除购物车？"),function(){
                        self.delCartNew();
                    });
                }else{
                    myApp.alert(_("请选择"));
                }
            });
			 //列表的勾选框裸钻 start
			$("#cart_stock_body").on("click",".check_rel",function(){
				$(this).children().find("span").toggleClass("selected");
				$(this).parent("tr").toggleClass("tr_select_color");
				//判断是否全选
				var length=$("#cart_stock_body tr.data_tr").length;
				var checkLength=$("#cart_stock_body .check_list_box span.selected").length;
				if(length==checkLength){
					$("#th_check_all_stock span").addClass("selected");
				}else{
					$("#th_check_all_stock span").removeClass("selected");
				}												
			});
			//选中重量
			$("#cart_stock_body").on("click","td.check_list_td",function(){
				$(this).prev().find("span").toggleClass("selected");
				$(this).parent("tr").toggleClass("tr_select_color");
				//判断是否全选
				var length=$("#cart_stock_body tr.data_tr").length;
				var checkLength=$("#cart_stock_body .check_list_box span.selected").length;
				if(length==checkLength){
					$("#th_check_all_stock span").addClass("selected");
				}else{
					$("#th_check_all_stock span").removeClass("selected");
				}								
			});
			//全选裸钻
			$("#th_check_all_stock").on("click",function(){
				var $this=$(this).children().children("span");
				$this.toggleClass("selected")
				if($this.hasClass("selected")){
					$("#cart_stock_body .check_list_box").children("span").addClass("selected");										
				}else{
					$("#cart_stock_body .check_list_box").children("span").removeClass("selected");
				}
			});
            //列表的勾选框裸钻 end

            //删除客户购物车start
            $("#cart_body").on("click",".check_rel",function(){
                $(this).children().find("span").toggleClass("selected");
                $(this).parent("tr").toggleClass("tr_select_color");
                //判断是否全选
                var length=$("#cart_body tr.data_tr").length;
                var checkLength=$("#cart_body .check_list_box span.selected").length;
                if(length==checkLength){
                    $("#th_check_all_stock_cart span").addClass("selected");
                }else{
                    $("#th_check_all_stock_cart span").removeClass("selected");
                }
            });

            $("#th_check_all_stock_cart").on("click",function(){
                var $this=$(this).children().children("span");
                $this.toggleClass("selected")
                if($this.hasClass("selected")){
                    $("#cart_body .check_list_box").children("span").addClass("selected");
                }else{
                    $("#cart_body .check_list_box").children("span").removeClass("selected");
                }
            });


            //列表的勾选框统包成品。。 start
            $("#parcel_cart_body,#inlay_cart_body,#inlaysettings_cart_body").on("click",".check_rel",function(){
                $(this).children().find("span").toggleClass("selected");
                $(this).parent("tr").toggleClass("tr_select_color");
                //判断是否全选
                var length;
                var checkLength;
				if(TYPE==2){
					length=$("#parcel_cart_body tr.data_tr").length;
					checkLength=$("#parcel_cart_body .check_list_box span.selected").length;
					if(length==checkLength){
						$("#th_check_all_parcels span").addClass("selected");
					}else{
						$("#th_check_all_parcels span").removeClass("selected");
					}
				}else if(TYPE==3){
                    length=$("#inlay_cart_body tr.data_tr").length;
                    checkLength=$("#inlay_cart_body .check_list_box span.selected").length;
                    if(length==checkLength){
                        $("#th_check_all_rings span").addClass("selected");
                    }else{
                        $("#th_check_all_rings span").removeClass("selected");
                    }
				}else if(TYPE==7){
                    length=$("#inlaysettings_cart_body tr.data_tr").length;
                    checkLength=$("#inlaysettings_cart_body .check_list_box span.selected").length;
                    if(length==checkLength){
                        $("#th_check_all_inlaysettings span").addClass("selected");
                    }else{
                        $("#th_check_all_inlaysettings span").removeClass("selected");
                    }
                }
            });
            //选中图片
            $("#parcel_cart_body,#inlay_cart_body,#inlaysettings_cart_body").on("click","td.check_list_td",function(){
                $(this).prev().find("span").toggleClass("selected");
                $(this).parent("tr").toggleClass("tr_select_color");
                //判断是否全选
				var length;
				var checkLength;
				if(TYPE==2){
					length=$("#parcel_cart_body tr.data_tr").length;
					checkLength=$("#parcel_cart_body .check_list_box span.selected").length;
					if(length==checkLength){
						$("#th_check_all_parcels span").addClass("selected");
					}else{
						$("#th_check_all_parcels span").removeClass("selected");
					}
				}else if(TYPE==3){
                    length=$("#inlay_cart_body tr.data_tr").length;
                    checkLength=$("#inlay_cart_body .check_list_box span.selected").length;
                    if(length==checkLength){
                        $("#th_check_all_rings span").addClass("selected");
                    }else{
                        $("#th_check_all_rings span").removeClass("selected");
                    }
				}else if(TYPE==7){
                    length=$("#inlaysettings_cart_body tr.data_tr").length;
                    checkLength=$("#inlaysettings_cart_body .check_list_box span.selected").length;
                    if(length==checkLength){
                        $("#th_check_all_inlaysettings span").addClass("selected");
                    }else{
                        $("#th_check_all_inlaysettings span").removeClass("selected");
                    }
                }
            });
            //全选
            $("#th_check_all_parcels,#th_check_all_rings,#th_check_all_inlaysettings").on("click",function(){
            	var $this;
            	if(TYPE==2){
					$this=$(this).children().children("span");
					$this.toggleClass("selected")
					if($this.hasClass("selected")){
						$("#parcel_cart_body .check_list_box").children("span").addClass("selected");
					}else {
                        $("#parcel_cart_body .check_list_box").children("span").removeClass("selected");
                    }
				}else if(TYPE==3){
					$this=$(this).children().children("span");
					$this.toggleClass("selected")
					if($this.hasClass("selected")){
						$("#inlay_cart_body .check_list_box").children("span").addClass("selected");
					}else{
						$("#inlay_cart_body .check_list_box").children("span").removeClass("selected");
					}

				}else if(TYPE==7){
                    $this=$(this).children().children("span");
                    $this.toggleClass("selected")
                    if($this.hasClass("selected")){
                        $("#inlaysettings_cart_body .check_list_box").children("span").addClass("selected");
                    }else{
                        $("#inlaysettings_cart_body .check_list_box").children("span").removeClass("selected");
                    }
                }
            });
            //列表的勾选框统包成品。。 end


		},
		//提交订单裸钻
		submitOrder:function(remarks){
			myApp.showIndicator();
			var self=this;
			//InventoryIDs值组装 _inventoryIDs="232,324"
            var cartlistCb = $("#cart_stock_body .check_rel span.selected");//tbody中checked的
            var _inventoryIDs = "";
            for (var i = 0; i < cartlistCb.length; i++) {
                if (i == 0)
                    _inventoryIDs += cartlistCb[i].lang;
                else
                    _inventoryIDs += "," + cartlistCb[i].lang;
            }
			var submitJson={};
			submitJson.CustomerID=id;			
			submitJson.InventoryIDs=_inventoryIDs;
			submitJson.OrderType=2;//1客户自己下单,2代下单
			submitJson.Remarks=remarks;
			 $.ajax({
                url: "/Team/SubmitOrder",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(submitJson),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象
                    myApp.hideIndicator();  //数据加载隐藏全屏遮罩层
                    $(".pop_bg_box").hide();
                    var tipWord="";
                    if (_result.msgcode == true) {
                    	if(_result.msginfo.Successful>0){
                    		tipWord+=_("成功")+_result.msginfo.Successful+"!";
                    	}
                    	if(_result.msginfo.Failed>0){
                    		tipWord+=_("失败")+_result.msginfo.Failed+_(",已下过单");
                    	}
                    	myApp.alert(tipWord);
                        self.GetCartInfos(id);
                    } else {
                        myApp.alert(_(_result.msginfo));
                    }
                }
            });
		},

		//提交订单统包 成品..
        submitOrderNew:function(remarks){
            myApp.showIndicator();
            var self=this;
            //InventoryIDs值组装 _inventoryIDs="232,324"
            var submitJson={};
            submitJson.CustomerID=id;
            var cartlistCb="";
            if(TYPE=="2"){
                submitJson.GoodsType=2;
                cartlistCb = $("#parcel_cart_body .check_rel span.selected");//tbody中checked的
            }else if(TYPE=="3"){
                submitJson.GoodsType=3;
                cartlistCb = $("#inlay_cart_body .check_rel span.selected");//tbody中checked的
            }else if(TYPE=="7"){
                submitJson.GoodsType=7;
                cartlistCb = $("#inlaysettings_cart_body .check_rel span.selected");//tbody中checked的
            }

            var _cartIDs = "";
            for (var i = 0; i < cartlistCb.length; i++) {
                if (i == 0)
                    _cartIDs += cartlistCb[i].lang;
                else
                    _cartIDs += "," + cartlistCb[i].lang;
            }


            submitJson.CartIDs=_cartIDs;
            submitJson.OrderType=2;//1客户自己下单,2代下单
            submitJson.Remarks=remarks;
            submitJson.UserID=UserID;


            $.ajax({
                url: "/Team/SubmitOrderNew",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(submitJson),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象
                    myApp.hideIndicator();  //数据加载隐藏全屏遮罩层
                    $(".pop_bg_box").hide();
                    var tipWord="";
                    if (_result.msgcode==false) {
                        myApp.alert(_(_result.msginfo));
                    } else {

                        if(_result.msginfo.Successful>0){
                            tipWord+=_("成功")+_result.msginfo.Successful+"!";
                        }
                        if(_result.msginfo.Failed>0){
                            tipWord+=_("失败")+_result.msginfo.Failed+_(",已下过单");
                        }
                        myApp.alert(tipWord);
                        self.GetCartInfos(id);
                    }
                }
            });
		},
		//删除裸钻
		delCart:function(){
			var self=this;
            var cartlistCb = $("#cart_stock_body .check_rel span.selected");//tbody中checked的
            var _inventoryIDs = "";
            for (var i = 0; i < cartlistCb.length; i++) {
                if (i == 0)
                    _inventoryIDs += cartlistCb[i].lang;
                else
                    _inventoryIDs += "," + cartlistCb[i].lang;
            }
            $.ajax({
                url: "/Customer/DeleteAllCart",//提交地址
                type: "POST",//提交方式
                data: "{'CustomerID':'" + id + "','InventoryIDs':'" + _inventoryIDs + "'}",
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象 
                    if (_result.msgcode == true) {
                    	myApp.alert(_(_result.msginfo));
                        self.GetCartInfos(id);
                         self.getCustomer(0);
                    } else {
                        myApp.alert(_(result.msginfo));
                    } 
                }
            });
		},

        //删除客户购物车
        delCusIDCart:function(){
            var self=this;
            var submitJson={};
            var cartlistCb = $("#cart_body .check_rel span.selected");//tbody中checked的
            var _customerIDs = "";
            for (var i = 0; i < cartlistCb.length; i++) {
                if (i == 0)
                    _customerIDs += cartlistCb[i].lang;
                else
                    _customerIDs += "," + cartlistCb[i].lang;
            }
            submitJson.CustomerIDs=_customerIDs;
            submitJson.GoodsType=TYPE;
            $.ajax({
                url: "/Team/RemoveCart",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(submitJson),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象
                    if (_result.msgcode == true) {
                        myApp.alert(_(_result.msginfo));
                        $("#th_check_all_stock_cart").find(".checkbox").removeClass("selected");
                        self.getCustomer(0);

                    } else {
                        myApp.alert(_(_result.msginfo));
                    }
                }
            });
        },

		//删除统包 成品。。
        delCartNew:function(){
            var self=this;
            var requestCart={};

            var cartlistCb;

            if(TYPE=="2"){
             	cartlistCb = $("#parcel_cart_body .check_rel span.selected");//tbody中checked的
                requestCart.GoodsType=2;
			}else if(TYPE=="3"){
                cartlistCb = $("#inlay_cart_body .check_rel span.selected");//tbody中checked的
                requestCart.GoodsType=3;
			}else if(TYPE == "7"){
                requestCart.GoodsType=7;
                cartlistCb = $("#inlaysettings_cart_body .check_rel span.selected");//tbody中checked的
            }
            var _cartIDs = "";
            for (var i = 0; i < cartlistCb.length; i++) {
                if (i == 0)
                    _cartIDs += cartlistCb[i].lang;
                else
                    _cartIDs += "," + cartlistCb[i].lang;
            }
            requestCart.CustomerID=id;
            requestCart.CartIDs=_cartIDs;
            $.ajax({
                url: "/team/RemoveCart",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(requestCart),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象
                    if (_result.msgcode == true) {
                        myApp.alert(_(_result.msginfo));
                        self.GetCartInfos(id);
                        self.getCustomer(0);
                    } else {
                        myApp.alert(_(result.msginfo));
                    }
                }
            });
		},
		//业务列表
		getSales:function(){
			var request ={};
            request.SysStatus =1;
            if (RoleID == 3 || RoleID == 6) {
                request.UserID =UserID;
            }else{
                request.UserID =$("#_salesUserID").val();
            }
            $.ajax({
                url: "/Team/GetSaleList",
                type: "POST",
                data: JSON.stringify(request),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');
                    if (_result.msgcode == false) {
                        var options_sales = "";
                        options_sales += '<option value="">' + _result.msginfo + '</option>';
                        $("#_salesUserID").html("");
                        $("#_salesUserID").html(options_sales);

                    } else {
                        var options_sales = "";
                        options_sales += '<option value="">'+_("业务")+'</option>';
                        for (var i = 0; i < _result.length; i++) {
                            options_sales += '<option value="' + _result[i].UserID + '"  >' + _result[i].RealName + '</option>';
                        }
                        $("#_salesUserID").html("");
                        $("#_salesUserID").html(options_sales);
                    }
                }
            });
		},
		//获取客户列表
		getCustomer:function(val){
			var requestCarts = {};
			myApp.showIndicator();
			if(val==0){
				// if (RoleID == 1) {
	                requestCarts.UserID =UserID;
	            // }else{
	            //     requestCarts.UserID =$("#_salesUserID").val();
	            // }
			}else if(val==1){
				if (RoleID == 3 || RoleID == 4 || RoleID == 5) {
	                requestCarts.UserID =UserID;
	            }else{
	                requestCarts.UserID = $("#_salesUserID option:checked").val();
	            }
	
	            requestCarts.CustomerNickName = $("#_customer").val();
	            requestCarts.CartType = $("#_cartType option:checked").val();
	
	            requestCarts.PageSize = 100;//单页数量
	            requestCarts.PageIndex = 1;//页码
			}else{
                requestCarts.UserID =UserID;
            }
            if(TYPE=="1"){
                requestCarts.GoodsType=1;
            }else if(TYPE=="2"){
                requestCarts.GoodsType=2;
            }else if(TYPE=="3"){
                requestCarts.GoodsType=3;
            }else if(TYPE=="4"){
                requestCarts.GoodsType=4;
            }else if(TYPE=="5"){
                requestCarts.GoodsType=5;
            }else if(TYPE=="6"){
                requestCarts.GoodsType=6;
            }else if(TYPE=="7"){
                requestCarts.GoodsType=7;
            }
            $.ajax({
                url:"/Team/GetCarts" ,//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(requestCarts),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                   var res=eval('('+result+')');
                  	if(res.msgcode==true){
                  		var $div=[];
                  		for(var i=0;i<res.msginfo.length;i++){
                  			var data=res.msginfo[i];
                  			$div.push(
                  				'<tr class="data_tr">',
                  					// '<td>',i+1,'</td>',
                  					'<td  class="check_rel"><div class="check_list_box"><span style="left:12px" class="checkbox" name="checkbox" lang="' + data.CustomerID + '"></span></div></td>',
                  					'<td>',data.CustomerNickName,'</td>',
                  					'<td>',data.SalesRealName,'</td>',
                  					'<td>',getCartType(data.CartType),'</td>',
                  					'<td>',data.Number,'</td>',
                  					'<td>',DateTimeFormat(data.CreateTime),'</td>',
                  					'<td class="check_toolbtn"><span class="look_cart" data-id=',data.CustomerID,'>'+_("查看")+'</span></td>',
                  				'</tr>'
                  			);
                  		}
                  		$("#cart_body").html($div.join(''));
                  	}else{

                  		$("#cart_body").html("<tr><td colspan='7'>"+_(res.msginfo)+"</td></tr>");
                  	}
                  	myApp.hideIndicator();
                }
            });
		},
		//获取客户对应的购物车
		GetCartInfos:function(id){
			myApp.showIndicator();
			var self=this;
			var submitJson={};
			submitJson.CustomerID=id;
			submitJson.PageSize=100;
			submitJson.PageIndex=1;
			submitJson.type=TYPE;
			var submit_url="/Team/GetCartInfos";
			
			$.ajax({
                url:submit_url ,//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(submitJson),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var res=eval('('+result+')');
                    if(res.msgcode==true){
                    	if(TYPE=="1"){
                    		$("#th_check_all_stock").find("span").removeClass("selected"); //去掉全选的勾选样式
                    		self.bindStockCart(res);
                    	}else if(TYPE=="2"){
                            $("#th_check_all_parcels").find("span").removeClass("selected");
							self.bindParcelCart(res);
						}else if(TYPE=="3"){
                            $("#th_check_all_rings").find("span").removeClass("selected");
                            self.bindInlayCart(res);
						}else if(TYPE=="4"){
							self.bindGemCart(res);
						}else if(TYPE=="5"){
							self.bindEmeraldCart(res);
						}else if(TYPE=="6"){
							self.bindPrimeGoldCart(res);
						}else if(TYPE=="7"){
                            $("#th_check_all_inlaysettings").find("span").removeClass("selected");
                            self.bindInlaySettingsCart(res);
                        }
                    }else{
                    	var resAlert=res.msginfo;

                        if(TYPE=="1"){

                            $("#th_check_all_stock").find("span").removeClass("selected");
                            res.msginfo={
                                Data:[]
                            }
                            self.bindStockCart(res);
                        }else if(TYPE=="2"){
                            $("#th_check_all_parcels").find("span").removeClass("selected");
                            res.msginfo={
                                rows:[]
                            }
                            self.bindParcelCart(res);
                        }else if(TYPE=="3"){
                            $("#th_check_all_rings").find("span").removeClass("selected");
                            res.msginfo={
                                rows:[]
                            }
                            self.bindInlayCart(res);
                        }else if(TYPE=="4"){
                            self.bindGemCart(res);
                        }else if(TYPE=="5"){
                            self.bindEmeraldCart(res);
                        }else if(TYPE=="6"){
                            self.bindPrimeGoldCart(res);
                        }else if(TYPE=="7"){
                            $("#th_check_all_inlaysettings").find("span").removeClass("selected");
                            res.msginfo={
                                rows:[]
                            }
                            self.bindInlaySettingsCart(res);
                        }
                    	myApp.alert(_(resAlert));
                    }
                    myApp.hideIndicator();
                }
            });
		},
        //绑定空托购物车
        bindInlaySettingsCart:function(res){
            if(res.msginfo.rows.length>0){
                var $cart=[];
                for(var i=0;i<res.msginfo.rows.length;i++){
                    var data=res.msginfo.rows[i];
                    $cart.push(
                        '<tr class="data_tr">',
                            "<td class='check_rel'>"+
                            '<div class="check_list_box"><span class="checkbox" name="checkbox" lang=',data.CartID,'></span></div></td>',
                            '<td class="check_list_td"><img src=',imgSrc(data.Images),' alt="" class="cart_tableImg"></td>',
                            '<td>',GetText("inlaysettings",1,data.IsStock,"IsStock"),'</td>',
                            '<td>',GetText("inlaysettings",1,data.Style,"Style"),'</td>',
                            '<td>',GetText("inlaysettings",1,data.Type,"Type"),'</td>',
                            '<td>',GetText("inlaysettings",1,data.Technics,"Technics"),'</td>',
                            '<td>',data.MainWeight,'</td>',
                            '<td>',data.TotalWeight,'</td>',
                            '<td>',GetText("inlaysettings",1,data.Material,"Material"),'</td>',
                            '<td>',formatRMBPrice(data.Price),'</td>',
                        '</tr>',
                        '<tr class="stock_detail">',
                        '<td colspan="11">',
                        '<div class="content-block">',
                        '<div class="row">',
                        '<div class="col-50">',
                        '<i><b>'+_("货号")+'：</b>',data.OriginSN,'</i>',
                        '<i><b>'+_("形状")+'：</b>',GetText("inlaysettings",1,data.MainShape,"MainShape"),'</i>',
                        '<i><b>'+_("尺寸")+'：</b>',data.Measurement,'</i>',
                        '</div>',
                        '<div class="col-50">',
                        '<i><b>'+_("所在地")+'：</b>',GetText("inlaysettings",1,data.Country,"Country"),'</i>',
                        '<i><b>'+_("状态")+'：</b>',GetText("inlaysettings",1,data.Status,"Status"),'</i>',
                        '<i><b>'+_("备注")+'：</b>',data.Remark,'</i>',
                        '</div>',
                        '</div>',
                        '</td>',
                        '</tr>'
                    );
                }
                $("#inlaysettings_cart_body").html($cart.join(''));
                currentShow();  //币种设置
            }else{
                var trs="<tr><td colspan='50'>"+_("暂时没有数据！")+"</td></tr>" ;
                $("#inlaysettings_cart_body").html(trs);
            }
        },
		//绑定素金购物车
		bindPrimeGoldCart:function(res){
			if(res.msginfo.rows.length>0){
				var $cart=[];
				for(var i=0;i<res.msginfo.rows.length;i++){
					var data=res.msginfo.rows[i];
					$cart.push(
						'<tr class="data_tr">',
							'<td class="check_rel"><div class="check_list_box"><span class="checkbox" name="checkbox" lang="' + _result[i].ID + '"></span></div></td>',
							'<td><img src=',imgSrc(data.Images),' alt="" class="cart_tableImg"></td>',
							'<td>',GetText("prime_golds",1,data.Type,"Type"),'</td>',
							'<td>',GetText("prime_golds",1,data.Style,"Style"),'</td>',
							'<td>',GetText("prime_golds",1,data.Material,"Material") ,'</td>',
							'<td>',GetText("prime_golds",1,data.Weight,"Weight"),'</td>',
							'<td>',data.StockNumber,'</td>',
							'<td>',formatRMBPrice(data.LaborFee),'</td>',
							'<td>',formatUSDPrice(data.GoldPrixce),'</td>',
						'</tr>',
						'<tr class="stock_detail">',
							'<td colspan="11">',
								'<div class="content-block">',
							      '<div class="row">',
							        '<div class="col-50">',
							        	'<i><b>'+_("货号")+'：</b>',data.OriginSN,'</i>',
							        	'<i><b>'+_("总重")+'：</b>',data.TotalWeight,'</i>',	
							        	'<i><b>'+_("系类名称")+'：</b>',data.Series,'</i>',							        	
							        	'<i><b>'+_("是否现货")+'：</b>',GetText("prime_golds",1,data.IsStock,"IsStock"),'</i>',							        							        								        	
							        '</div>',
							        '<div class="col-50">',
							        	'<i><b>'+_("成品证书")+'：</b>',data.CertType,'</i>',	
							        	'<i><b>'+_("供应商")+'：</b>',data.Supplier,'</i>',
							        	'<i><b>'+_("所在地")+'：</b>',data.Country,data.State,'</i>',
							        	'<i><b>'+_("备注")+'：</b>',data.Remark,'</i>',
							        '</div>',
							        '<div class="col-100">',
							        	'<i><b>'+_("详情")+'：</b>',data.Details,'</i>',	
							        '</div>',
							      '</div>',
							'</td>',
						'</tr>'
					);
				}
				$("#PrimeGold_cart_body").html($cart.join(''));
			}else{
				var trs="<tr><td colspan='50'>"+_("暂时没有数据！")+"</td></tr>" ;
            	$("#PrimeGold_cart_body").html(trs);
			}
		},
		//绑定翡翠购物车
		bindEmeraldCart:function(res){
			if(res.msginfo.rows.length>0){
				var $cart=[];
				for(var i=0;i<res.msginfo.rows.length;i++){
					var data=res.msginfo.rows[i];
					$cart.push(
						'<tr class="data_tr">',
							'<td>',i+1,'</td>',
							'<td><img src=',imgSrc(data.Images),' alt="" class="cart_tableImg"></td>',
							'<td>',GetText("emeralds",1,data.Type,"Type"),'</td>',
							'<td>',getEmeraldType(data.Type,data.Type2,"Type2"),'</td>',
							'<td>',GetText("emeralds",1,data.Texture,"Texture"),'</td>',
							'<td>',data.Color,'</td>',
							'<td>',data.Weight,'</td>',
//							'<td>',formatRMBPrice(data.Price),'</td>',
//							'<td>',formatUSDPrice(data.Price/EmeraldRate),'</td>',
							'<td>',GetText("emeralds",data.Category,data.Status,"Status"),'</td>',showPriceType(data,EmeraldRate),
						'</tr>',
						'<tr class="stock_detail">',
							'<td colspan="11">',
								'<div class="content-block">',
							      '<div class="row">',
							        '<div class="col-50">',
							        	'<i><b>'+_("证书")+'：</b>',data.CertType,'</i>',
							        	'<i onclick="showTotalWord(this)"><b>'+_("证书号")+'：</b><span>',data.CertNo,'</span></i>',
							        	'<i onclick="showTotalWord(this)"><b>'+_("尺寸")+'：</b><span>',data.Measurement,'</span></i>',	
							        	'<i class="CurrentRMB"><b>￥/Pkg：</b>',formatRMBPrice(data.Price),'</i>',
							        	'<i class="CurrentUSD"><b>$/Pkg：</b>',formatUSDPrice(data.Price/EmeraldRate),'</i>',
							        '</div>',
							        '<div class="col-50">',
							        	'<i><b>'+_("系列名称")+'：</b>',data.Name,'</i>',	
							        	'<i><b>'+_("货号")+'：</b>',data.OriginSN,'</i>',	
							        	'<i><b>'+_("供应商")+'：</b>',data.Supplier,'</i>',
							        	'<i><b>'+_("所在地")+'：</b>',GetText("emeralds",data.Category,data.Country,"Country"),'</i>',
							        '</div>',
							      '</div>',
							'</td>',
						'</tr>'
					);
				}
				$("#emerald_cart_body").html($cart.join(''));
				currentShow();  //币种设置
			}else{
				var trs="<tr><td colspan='50'>"+_("暂时没有数据！")+"</td></tr>" ;
            	$("#emerald_cart_body").html(trs);
			}
		},
		//绑定彩宝购物车
		bindGemCart:function(res){
			if(res.msginfo.rows.length>0){
				var $cart=[];
				for(var i=0;i<res.msginfo.rows.length;i++){
					var data=res.msginfo.rows[i];
					$cart.push(
						'<tr class="data_tr">',
							'<td>',i+1,'</td>',
							'<td><img src=',imgSrc(data.Images),' alt="" class="cart_tableImg"></td>',
							'<td>',GetCategory("gems",data.Category),'</td>',
							'<td>',GetText("gems",data.Category,data.Place,"Place"),'</td>',
							'<td>',GetText("gems",data.Category,data.Shape,"Shape"),'</td>',
							'<td>',data.Weight,'</td>',
							'<td>',data.Cut,'</td>',
							'<td>',GetText("gems",data.Category,data.Color,"Color"),'</td>',showPriceType(data,GemRate),
						'</tr>',
						'<tr class="stock_detail">',
							'<td colspan="11">',
								'<div class="content-block">',
							      '<div class="row">',
							        '<div class="col-50">',
//							        	'<i><b>颜色：</b>',GetText("gems",data.Category,data.Color,"Color"),'</i>',
							        	'<i><b>'+_("处理")+'：</b>',GetText("gems",data.Category,data.Process,"Process"),'</i>',
							        	'<i><b>'+_("油性")+'：</b>',GetText("gems",data.Category,data.Oiliness,"Oiliness"),'</i>',	
							        	'<i><b>'+_("切工方式")+'：</b>',GetText("gems",data.Category,data.CutMethod,"CutMethod"),'</i>',
							        	'<i><b>'+_("尺寸")+'：</b>',data.Measurement,'</i>',	
							        	'<i class="CurrentRMB"><b>￥/Pkg：</b>',formatRMBPrice(data.Price),'</i>',
							        	'<i class="CurrentUSD"><b>$/Pkg：</b>',formatUSDPrice(data.Price/GemRate),'</i>',
							        '</div>',
							        '<div class="col-50">',
							        	'<i><b>'+_("货号")+'：</b>',data.OriginSN,'</i>',	
							        	'<i><b>'+_("供应商")+'：</b>',data.Supplier,'</i>',
							        	'<i><b>'+_("所在地")+'：</b>',GetText("gems",data.Category,data.Country,"Country"),'</i>',
							        	'<i><b>'+_("状态")+'：</b>',GetText("gems",data.Category,data.Status,"Status"),'</i>',
							        	'<i><b>'+_("备注")+'：</b>',data.Remark,'</i>',
							        '</div>',
							      '</div>',
							'</td>',
						'</tr>'
					);
				}
				$("#gem_cart_body").html($cart.join(''));
				currentShow();  //币种设置
			}else{
				var trs="<tr><td colspan='50'>"+_("暂时没有数据！")+"</td></tr>" ;
            	$("#gem_cart_body").html(trs);
			}
		},
		//绑定成品购物车
		bindInlayCart:function(res){
			if(res.msginfo.rows.length>0){
				var $cart=[];
				for(var i=0;i<res.msginfo.rows.length;i++){
					var data=res.msginfo.rows[i];
                    var ringSupplier='';
                    if(isHideSupplier == "1"){
                        ringSupplier='<i><b>'+_("供应商")+'：</b>'+data.Supplier+'</i>'
                    }
					$cart.push(
						'<tr class="data_tr">',
							"<td class='check_rel'>"+
							'<div class="check_list_box"><span class="checkbox" name="checkbox" lang=',data.CartID,'></span></div></td>',
							'<td class="check_list_td"><img src=',imgSrc(data.Images),' alt="" class="cart_tableImg"></td>',
							'<td>',GetText("inlays",data.Category,data.IsStock,"IsStock"),'</td>',
							'<td>',GetCategory("inlays",data.Category),'</td>',
							'<td>',getBicon(GetText("inlays",data.Category,data.MainShape,"MainShape")),'</td>',
							'<td>',GetText("inlays",data.Category,data.Type,"Type"),'</td>',
							'<td>',data.Weight,'</td>',
							'<td>',GetText("inlays",data.Category,data.Material,"Material"),'</td>',
							'<td>',data.MainClarity?data.MainClarity:"-",'</td>',showPriceType(data,RingRate),
						'</tr>',
						'<tr class="stock_detail">',
							'<td colspan="11">',
								'<div class="content-block">',
							      '<div class="row">',
							        '<div class="col-50">',
							        	'<i><b>'+_("颜色")+'：</b>',GetText("inlays",data.Category,data.MainColor,"MainColor"),'</i>',
							        	'<i><b>'+_("主石重量")+'：</b>',data.MainWeight,'</i>',	
							        	'<i><b>'+_("风格")+'：</b>',GetText("inlays",data.Category,data.Style,"Style"),'</i>',
							        	'<i><b>'+_("尺寸")+'：</b>',data.Measurement,'</i>',
							        	'<i class="CurrentRMB"><b>￥/Pkg：</b>',formatRMBPrice(data.Price),'</i>',
							        	'<i class="CurrentUSD"><b>$/Pkg：</b>',formatUSDPrice(data.Price/RingRate),'</i>',
							        '</div>',
							        '<div class="col-50">',
							        	'<i><b>'+_("货号")+'：</b>',data.OriginSN,'</i>',	
							        	// '<i><b>'+_("供应商")+'：</b>',data.Supplier,'</i>',
                                        ringSupplier,
							        	'<i><b>'+_("所在地")+'：</b>',GetText("inlays",data.Category,data.Country,"Country"),'</i>',
							        	'<i><b>'+_("状态")+'：</b>',GetText("inlays",data.Category,data.Status,"Status"),'</i>',
							        	'<i><b>'+_("备注")+'：</b>',data.Remark,'</i>',
							        '</div>',
							      '</div>',
							'</td>',
						'</tr>'
					);
				}
				$("#inlay_cart_body").html($cart.join(''));
				currentShow();  //币种设置
			}else{
				var trs="<tr><td colspan='50'>"+_("暂时没有数据！")+"</td></tr>" ;
            	$("#inlay_cart_body").html(trs);
			}
		},
		//绑定统包购物车
		bindParcelCart:function(res){
			console.log(res)
			if(res.msginfo.rows.length>0){
				var $cart=[];
				for(var i=0;i<res.msginfo.rows.length;i++){
					var data=res.msginfo.rows[i];

					$cart.push(
						'<tr class="data_tr">',
							"<td class='check_rel'>"+
							'<div class="check_list_box"><span class="checkbox" name="checkbox" lang=',data.CartID,'></span></div></td>',
							'<td class="check_list_td"><img src=',imgSrc(data.Images),' alt="" class="cart_tableImg"></td>',
							'<td>',GetCategory("parcels",data.Category),'</td>',
							'<td>',getBicon(GetText("parcels",data.Category,data.Shape,"Shape")),'</td>',
							'<td>',data.Size,'</td>',
							'<td>',data.Weight,'</td>',
							'<td>',ParcelRate,'</td>',
							'<td>',data.MainClarity?data.MainClarity:"-",'</td>',showPriceType(data,ParcelRate),
						'</tr>',
						'<tr class="stock_detail">',
							'<td colspan="11">',
								'<div class="content-block">',
							      '<div class="row">',
							        '<div class="col-50">',
							        	'<i><b>'+_("颜色")+'：</b>',GetText("parcels",data.Category,data.Color,"Color"),'</i>',
							        	'<i><b>'+_("净度")+'：</b>',data.Clarity?data.Clarity:"-",'</i>',
							        	'<i><b>'+_("货号")+'：</b>',data.OriginSN,'</i>',							        	
							        	'<i><b>'+_("状态")+'：</b>',GetText("parcels",data.Category,data.Status,"Status"),'</i>',
							        	'<i><b>'+_("供应商")+'：</b>',data.Supplier,'</i>',
							        '</div>',
							        '<div class="col-50">',
                                        '<i class="CurrentUSD"><b>$/Ct：</b>',formatRMBPrice(parseFloat((data.Price) )),'</i>',
                                        '<i class="CurrentUSD"><b>卖$：</b>',formatRMBPrice(parseFloat(data.Price*data.InventoryCount)),'</i>',
							        	'<i class="CurrentRMB"><b>￥/Ct：</b>',formatRMBPrice(parseFloat((data.Price) * ParcelRate)),'</i>',
							        	'<i class="CurrentRMB"><b>卖￥：</b>',formatRMBPrice(parseFloat(data.Price*data.InventoryCount * ParcelRate)),'</i>',
							        	'<i><b>'+_("所在地")+'：</b>',GetText("parcels",data.Category,data.Place,"Place"),'</i>',
							        	'<i><b>'+_("购买重量")+'：</b>',data.InventoryCount,'</i>',
							        '</div>',
							      '</div>',
							'</td>',
						'</tr>'
					);
				}
				$("#parcel_cart_body").html($cart.join(''));
				currentShow();  //币种设置
			}else{
				var trs="<tr><td colspan='50'>"+_("暂时没有数据！")+"</td></tr>" ;
            	$("#parcel_cart_body").html(trs);
			}
		},
		//绑定裸钻购物车
		bindStockCart:function(res){
			$("#th_check_all_stock span").removeClass("selected");
			if(res.msginfo.Data.length>0){				
                var trs = "";//多行数据
				for(var i=0;i<res.msginfo.Data.length;i++){
					var tds = "";//多列
	                var tr = "";//单行
	                var tr_div = "";
					var data=res.msginfo.Data[i];
	                tds += "<td class='check_rel'>"+
	                "<div class='check_list_box'><span class='checkbox' name='checkbox' lang='" + data.ID + "'></span></div></td>";
	                tds += "<td class='check_list_td'>" + data.Weight + "</td>";
	                tds += "<td>" +ColorFormat(data.Color) + "</td>";
	                tds += "<td>" + data.Clarity + "</td>";
	                tds += "<td>" + data.Cut + "</td>";
	                tds += "<td>" + data.Polish + "</td>";
	                tds += "<td>" + data.Symmetry + "</td>";
	                tds += "<td>" + data.Fluorescence + "</td>";
	                tds += "<td>" + ValueFormat(data.CustomerDiscountReturn) + "</td>";
	                if($.cookie("CurrentSet") == 2){ //美金
                		tds += "<td>"+formatRMBPrice(data.DolarPerCarat)+"</td>";	
		               	tds += "<td style='font-weight:bold' class=''>" + formatUSDPrice(data.DolarPerGrain) + "</td>";//四舍五入
		            }else{ //全局0和人民币1显示人民币
		            	tds += "<td>"+formatRMBPrice(data.CustomerRMBPerCarat)+"</td>";	               
	                	tds += "<td style='font-weight:bold' class='td_second'>" + formatRMBPrice(data.CustomerRMBPerGrain) + "</td>";//四舍五入
		            }
	                tr += "<tr class='data_tr'>" + tds + "</tr>";//将多列加到一行onclick=\"click_change_tr_color(this)\"
	                tr_div="<tr class='stock_detail'><td  colspan='50'>"+
	                "<div class='detail_left' style='width:50%;'>"+
	                	"<i onclick='showTotalWord(this)'><b  class='custrom'>"+_("货号")+"：</b><span>" + data.SN + "</span></i>" +
	                	"<i><b>"+_("形状")+"：</b>"+GetText("stocks",1,data.Shape,"Shape")+"</i>"+
	                	"<i><b>"+_("奶油")+"：</b>" + MilkyFormat(data.Milky) + "</i>" +
	                	"<i><b>"+_("色调")+"：</b>" + HueFormat(data.Hue) + "</i>" +
	                	"<i><b>"+_("星箭")+"：</b>" + HAFormat(data.HA) + "</i>" +
	                	"<i onclick='showTotalWord(this)'><b class='custrom'>"+_("黑点")+"：</b><span>" + BlackDefectFormat(data.BlackDefect) + "</span></i>" +
	                	"<i onclick='showTotalWord(this)'><b class='custrom'>"+_("瑕疵")+"：</b><span>" + OtherDefectFormat(data.OtherDefect) + "</span></i>"+
	                	"<i><b>"+_("状态")+"：</b>" + GetText("stocks",1,data.Status,"Status") + "</i>" +
	                	"<i><b>"+_("所在地")+"：</b>" + GetText("stocks",1,data.Place,"Place") + "</i>" +
	                "</div>" +
	                "<div class='detail_right' style='width:50%;'>"+
	                	"<i><b class='custrom'>"+_("类型")+"：</b>" + CertTypeFormat(data) + "</i>"+	                	                	
	                	"<i onclick='showTotalWord(this)'><b class='custrom'>"+_("尺寸")+"：</b><span>" + data.Measurement + "</span></i>"+
	                	"<i><b>"+_("Rap")+"：</b>" + formatUSDPrice(data.Rapnet) + "</i>" +
		                "<i class='CurrentUSD'><b>$/Ct：</b>"+formatUSDPrice(data.DolarPerCarat)+"</i>"+
	                	"<i class='CurrentUSD'><b>$/Pcs：</b>" + formatUSDPrice(data.DolarPerGrain) + "</i>" +
	                	"<i class='CurrentRMB'><b>￥/Ct：</b>" + formatRMBPrice(data.CustomerRMBPerCarat) + "</i>" +
	                	"<i class='CurrentRMB'><b>￥/Pcs：</b>" + formatRMBPrice(data.CustomerRMBPerGrain) + "</i>" +
	                	"<i><b class='custrom'>"+_("上传")+"：</b><span>" + DateTimeHandler(data.UpdateTime) + "</span></i>"+
	                "</div></td></tr>";
	                trs += tr+tr_div;//将单行加到多行
				} 
				$("#cart_stock_body").html(trs);
				currentShow();  //币种设置
           }else{
            	trs="<tr><td colspan='50'>"+_("暂时没有数据！")+"</td></tr>" ;
            	$("#cart_stock_body").html(trs);
            }
		},
	}
	
	cart.init();
})();
 //购物车来源
function getCartType(cartValue) {
    if (cartValue == 1) {
        return _("电脑端");
    } else if (cartValue == 2) {
        return _("苹果端");
    } else if (cartValue == 3) {
        return _("安卓端");
    }else if(cartValue == 4){
    	return _("移动端");
	}
}
//返回图片链接
function imgSrc(images) {
    if (images) {
        images = images.split('|');
        var small = images[0];
        var big = small.replace('400x400', '1920x1920');
        return small;
    }
    return '../images/no_img.jpg';//无图时返回默认图片
}

//价格显示
function showPriceType(data,rate) {
	
	if(TYPE==2){ //统包获取的是美金每卡价格
		if($.cookie("CurrentSet") == 2) { //美金
			return '<td>'+formatUSDPrice(data.Price*data.Weight)+'</td>';
		}
		else { //全局0和人民币1显示人民币
			return '<td>'+formatRMBPrice(data.Price*data.Weight*rate)+'</td>';
		}
	}else{
		if($.cookie("CurrentSet") == 2) { //美金
			return '<td>'+formatUSDPrice(data.Price / rate)+'</td>';
		}
		else { //全局0和人民币1显示人民币
			return '<td>'+formatRMBPrice(data.Price)+'</td>';
		}
	}
}
